Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 379)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.47181 11.51755 11.56262 11.60705 11.65085 11.69404 11.73664 11.77867
## [9] 11.82015 11.86110 11.90153 11.94146 11.98092 12.01991 12.05847 12.09659
## [17] 12.13426 12.17145 12.20811 12.24422 12.27974 12.31463 12.34887 12.38241
## [25] 12.41522 12.44727 12.47852 12.50944 12.54036 12.57110 12.60145 12.63122
## [33] 12.66020 12.68820 12.71502 12.74046 12.76568 12.79172 12.81826 12.84494
## [41] 12.87143 12.89738 12.92246 12.94633 12.96864 12.98905 13.00722 13.02281
## [49] 13.03717 13.05171 13.06616 13.08029 13.09382 13.10652 13.11812 13.12837
## [57] 13.13702 13.14381 13.14849 13.15081 13.15051 13.14734 13.14044 13.12964
## [65] 13.11566 13.09926 13.08116 13.06212 13.04287 13.02415 13.00670 12.98671
## [73] 12.96063 12.92957 12.89466 12.85700 12.81773 12.77796 12.73881 12.70140
## [81] 12.66684 12.63627 12.61079 12.58626 12.55849 12.52850 12.49734 12.46603
## [89] 12.43562 12.40714 12.38162 12.36010 12.34117 12.32273 12.30484 12.28754
## [97] 12.27087 12.25488 12.23960 12.22509 12.21138 12.19853 12.18656 12.17553
## [105] 12.16547 12.15644 12.14909 12.14385 12.14045 12.13862 12.13808 12.13857
## [113] 12.13980 12.14150 12.14341 12.14524 12.14673 12.14759 12.14978 12.15491
## [121] 12.16222 12.17095 12.18034 12.18961 12.19801 12.20478 12.20916 12.21246
## [129] 12.21644 12.22097 12.22589 12.23108 12.23639 12.24169 12.24685 12.25171
## [137] 12.25615 12.26002 12.26320 12.26499 12.26501 12.26360 12.26110 12.25782
## [145] 12.25412 12.25030 12.24672 12.24369 12.24155 12.24063 12.24127 12.24379
## [153] 12.24853 12.25582 12.26598 12.27843 12.29224 12.30721 12.32319 12.33999
## [161] 12.35743 12.37535 12.39355 12.41186 12.43011 12.44812 12.46572 12.48660
## [169] 12.51385 12.54637 12.58305 12.62278 12.66445 12.70696 12.74920 12.79006
## [177] 12.82843 12.86321 12.89330 12.91757 12.93493 12.94994 12.96747 12.98684
## [185] 13.00740 13.02847 13.04939 13.06949 13.08811 13.10457 13.11821 13.12836
## [193] 13.13435 13.13552 13.13120 13.12086 13.10483 13.08379 13.05841 13.02935
## [201] 12.99729 12.96289 12.92683 12.88976 12.85237 12.81531 12.77925 12.74488
## [209] 12.71284 12.67701 12.63234 12.58118 12.52586 12.46870 12.41205 12.35823
## [217] 12.30959 12.26844 12.23018 12.18906 12.14576 12.10093 12.05525 12.00939
## [225] 11.96400 11.91975 11.87732 11.83736 11.80054 11.76753 11.73584 11.70300
## [233] 11.66967 11.63650 11.60417 11.57332 11.54462 11.51873 11.49631 11.47587
## [241] 11.45564 11.43584 11.41670 11.39843 11.38126 11.36542 11.35112 11.33860
## [249] 11.32807 11.31976 11.31389 11.31068 11.31037 11.31457 11.32420 11.33839
## [257] 11.35628 11.37701 11.39970 11.42350 11.44755 11.47097 11.49291 11.51250
## [265] 11.52887 11.54741 11.57280 11.60317 11.63664 11.67133 11.70536 11.73685
## [273] 11.76392 11.78470 11.80238 11.82127 11.84110 11.86160 11.88250 11.90353
## [281] 11.92444 11.94494 11.96477 11.98368 12.00138 12.01761 12.03207 12.04482
## [289] 12.05612 12.06624 12.07543 12.08396 12.09210 12.10010 12.10824 12.11677
## [297] 12.12595 12.13605 12.14734 12.16007 12.17320 12.18558 12.19733 12.20857
## [305] 12.21944 12.23005 12.24054 12.25101 12.26161 12.27244 12.28365 12.29534
## [313] 12.30765 12.32070 12.33612 12.35484 12.37595 12.39851 12.42160 12.44430
## [321] 12.46568 12.48481 12.50078 12.51552 12.53143 12.54822 12.56565 12.58343
## [329] 12.60129 12.61897 12.63620 12.65271 12.66823 12.68249 12.69523 12.70617
## [337] 12.71538 12.72325 12.72995 12.73567 12.74060 12.74491 12.74879 12.75243
## [345] 12.75600 12.75970 12.76370 12.76820 12.77336 12.77856 12.78309 12.78707
## [353] 12.79061 12.79384 12.79687 12.79980 12.80277 12.80587 12.80892 12.81166
## [361] 12.81410 12.81626 12.81818 12.81985 12.82132 12.82259 12.82369 12.82464
## [369] 12.82546 12.82617 12.82683 12.82750 12.82812 12.82866 12.82909 12.82937
## [377] 12.82946 12.82932 12.82892
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 379)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.76139 10.84828 10.93354 11.01716 11.09910 11.17937 11.25794 11.33479
## [9] 11.40992 11.48331 11.55493 11.62478 11.69284 11.75909 11.82352 11.88612
## [17] 11.94690 12.00589 12.06313 12.11865 12.17247 12.22463 12.27515 12.32407
## [25] 12.37142 12.41723 12.46152 12.50397 12.54432 12.58270 12.61926 12.65414
## [33] 12.68747 12.71940 12.75007 12.77961 12.80708 12.83160 12.85347 12.87299
## [41] 12.89045 12.90615 12.92039 12.93345 12.94563 12.95722 12.96853 12.97985
## [49] 12.98950 12.99588 12.99939 13.00043 12.99939 12.99668 12.99270 12.98783
## [57] 12.98247 12.97704 12.97191 12.96750 12.96419 12.96239 12.96188 12.96196
## [65] 12.96227 12.96248 12.96225 12.96124 12.95909 12.95548 12.95006 12.94291
## [73] 12.93446 12.92484 12.91418 12.90264 12.89036 12.87747 12.86411 12.85043
## [81] 12.83656 12.82266 12.80885 12.79537 12.78222 12.76916 12.75593 12.74231
## [89] 12.72806 12.71294 12.69671 12.67912 12.65922 12.63647 12.61129 12.58408
## [97] 12.55528 12.52528 12.49452 12.46339 12.43233 12.40174 12.37205 12.34366
## [105] 12.31700 12.29247 12.26573 12.23306 12.19585 12.15548 12.11335 12.07083
## [113] 12.02931 11.99019 11.95484 11.92465 11.90101 11.88530 11.87487 11.86611
## [121] 11.85891 11.85321 11.84891 11.84594 11.84420 11.84362 11.84412 11.84690
## [129] 11.85294 11.86182 11.87308 11.88629 11.90102 11.91682 11.93327 11.94992
## [137] 11.96633 11.98207 11.99670 12.01281 12.03295 12.05663 12.08340 12.11277
## [145] 12.14426 12.17740 12.21171 12.24672 12.28195 12.31693 12.35117 12.38421
## [153] 12.41556 12.44476 12.47132 12.49733 12.52496 12.55380 12.58349 12.61361
## [161] 12.64380 12.67366 12.70281 12.73086 12.75742 12.78211 12.80453 12.82612
## [169] 12.84841 12.87118 12.89423 12.91733 12.94028 12.96286 12.98486 13.00605
## [177] 13.02624 13.04520 13.06272 13.07859 13.09259 13.10717 13.12448 13.14389
## [185] 13.16472 13.18634 13.20809 13.22931 13.24936 13.26758 13.28333 13.29594
## [193] 13.30477 13.30916 13.30847 13.30363 13.29612 13.28611 13.27378 13.25930
## [201] 13.24283 13.22457 13.20467 13.18331 13.16066 13.13689 13.11219 13.08671
## [209] 13.06063 13.02974 12.99100 12.94640 12.89793 12.84756 12.79729 12.74909
## [217] 12.70495 12.66684 12.63021 12.58964 12.54587 12.49966 12.45174 12.40286
## [225] 12.35374 12.30514 12.25779 12.21244 12.16983 12.13069 12.09120 12.04788
## [233] 12.00201 11.95486 11.90770 11.86182 11.81849 11.77898 11.74457 11.71299
## [241] 11.68129 11.64973 11.61855 11.58802 11.55838 11.52990 11.50283 11.47742
## [249] 11.45393 11.43261 11.41372 11.39752 11.38425 11.37421 11.36729 11.36317
## [257] 11.36152 11.36201 11.36434 11.36816 11.37315 11.37900 11.38537 11.39194
## [265] 11.39839 11.40716 11.42028 11.43675 11.45560 11.47585 11.49652 11.51662
## [273] 11.53518 11.55121 11.56701 11.58526 11.60558 11.62760 11.65094 11.67522
## [281] 11.70007 11.72511 11.74996 11.77424 11.79759 11.81961 11.84210 11.86685
## [289] 11.89349 11.92165 11.95097 11.98107 12.01159 12.04215 12.07240 12.10197
## [297] 12.13048 12.15756 12.18286 12.20600 12.22787 12.24960 12.27114 12.29247
## [305] 12.31355 12.33436 12.35487 12.37504 12.39484 12.41424 12.43321 12.45172
## [313] 12.46974 12.48723 12.50428 12.52099 12.53736 12.55341 12.56914 12.58457
## [321] 12.59971 12.61456 12.62914 12.64360 12.65806 12.67246 12.68675 12.70086
## [329] 12.71474 12.72834 12.74159 12.75444 12.76682 12.77869 12.78999 12.80065
## [337] 12.81042 12.81916 12.82703 12.83417 12.84075 12.84692 12.85282 12.85862
## [345] 12.86447 12.87051 12.87690 12.88380 12.89136 12.89904 12.90626 12.91311
## [353] 12.91970 12.92611 12.93244 12.93878 12.94522 12.95186 12.95854 12.96504
## [361] 12.97138 12.97757 12.98364 12.98960 12.99547 13.00126 13.00700 13.01270
## [369] 13.01838 13.02405 13.02977 13.03555 13.04138 13.04723 13.05306 13.05884
## [377] 13.06455 13.07016 13.07564
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 379)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.85740 10.91761 10.97680 11.03496 11.09208 11.14815 11.20316 11.25711
## [9] 11.30997 11.36175 11.41243 11.46199 11.51044 11.55775 11.60393 11.64900
## [17] 11.69303 11.73600 11.77793 11.81880 11.85864 11.89743 11.93518 11.97188
## [25] 12.00755 12.04218 12.07578 12.10805 12.13881 12.16820 12.19636 12.22342
## [33] 12.24952 12.27482 12.29944 12.32353 12.34688 12.36922 12.39059 12.41099
## [41] 12.43047 12.44904 12.46673 12.48358 12.49960 12.51483 12.52928 12.54299
## [49] 12.55622 12.56915 12.58167 12.59369 12.60509 12.61577 12.62563 12.63457
## [57] 12.64247 12.64925 12.65479 12.65899 12.66175 12.66297 12.66219 12.65928
## [65] 12.65457 12.64840 12.64111 12.63304 12.62453 12.61592 12.60755 12.59783
## [73] 12.58525 12.57025 12.55328 12.53479 12.51522 12.49501 12.47461 12.45447
## [81] 12.43502 12.41672 12.40002 12.38134 12.35778 12.33076 12.30169 12.27200
## [89] 12.24312 12.21645 12.19343 12.17547 12.16092 12.14717 12.13413 12.12175
## [97] 12.10995 12.09868 12.08786 12.07744 12.06734 12.05749 12.04784 12.03832
## [105] 12.02886 12.01939 12.01011 12.00126 11.99281 11.98476 11.97709 11.96979
## [113] 11.96286 11.95626 11.95001 11.94407 11.93844 11.93311 11.92932 11.92790
## [121] 11.92823 11.92968 11.93162 11.93343 11.93447 11.93412 11.93176 11.92798
## [129] 11.92384 11.91945 11.91490 11.91026 11.90565 11.90114 11.89683 11.89280
## [137] 11.88916 11.88598 11.88337 11.87958 11.87315 11.86457 11.85434 11.84296
## [145] 11.83092 11.81872 11.80686 11.79582 11.78611 11.77821 11.77264 11.76987
## [153] 11.77042 11.77477 11.78342 11.79608 11.81183 11.83022 11.85081 11.87315
## [161] 11.89679 11.92128 11.94618 11.97103 11.99539 12.01882 12.04086 12.06532
## [169] 12.09568 12.13096 12.17021 12.21247 12.25677 12.30215 12.34766 12.39233
## [177] 12.43520 12.47531 12.51170 12.54340 12.56946 12.59491 12.62478 12.65812
## [185] 12.69398 12.73140 12.76943 12.80711 12.84349 12.87762 12.90854 12.93529
## [193] 12.95692 12.97248 12.98102 12.98346 12.98165 12.97599 12.96686 12.95469
## [201] 12.93985 12.92276 12.90381 12.88341 12.86194 12.83982 12.81744 12.79519
## [209] 12.77349 12.74675 12.71076 12.66790 12.62057 12.57116 12.52208 12.47572
## [217] 12.43447 12.40074 12.36818 12.32968 12.28646 12.23973 12.19073 12.14068
## [225] 12.09078 12.04227 11.99637 11.95429 11.91726 11.88651 11.85804 11.82766
## [233] 11.79629 11.76483 11.73418 11.70526 11.67897 11.65621 11.63790 11.62474
## [241] 11.61640 11.61223 11.61157 11.61378 11.61821 11.62422 11.63114 11.63833
## [249] 11.64515 11.65094 11.65505 11.65683 11.65564 11.65294 11.65066 11.64881
## [257] 11.64743 11.64655 11.64619 11.64638 11.64715 11.64852 11.65053 11.65320
## [265] 11.65656 11.65996 11.66293 11.66574 11.66867 11.67200 11.67600 11.68094
## [273] 11.68710 11.69476 11.70359 11.71303 11.72300 11.73343 11.74424 11.75536
## [281] 11.76672 11.77825 11.78986 11.80149 11.81307 11.82451 11.83690 11.85119
## [289] 11.86709 11.88431 11.90257 11.92159 11.94108 11.96075 11.98033 11.99953
## [297] 12.01806 12.03564 12.05198 12.06681 12.08149 12.09743 12.11439 12.13212
## [305] 12.15039 12.16895 12.18757 12.20599 12.22397 12.24129 12.25768 12.27291
## [313] 12.28674 12.29893 12.30930 12.31804 12.32547 12.33192 12.33770 12.34313
## [321] 12.34854 12.35423 12.36053 12.36706 12.37324 12.37908 12.38462 12.38986
## [329] 12.39482 12.39953 12.40399 12.40822 12.41225 12.41610 12.41977 12.42329
## [337] 12.42672 12.43008 12.43332 12.43640 12.43928 12.44190 12.44422 12.44619
## [345] 12.44778 12.44893 12.44959 12.44973 12.44930 12.44844 12.44734 12.44596
## [353] 12.44427 12.44226 12.43990 12.43717 12.43402 12.43045 12.42650 12.42220
## [361] 12.41757 12.41260 12.40730 12.40166 12.39567 12.38935 12.38268 12.37566
## [369] 12.36831 12.36060 12.35256 12.34418 12.33548 12.32644 12.31706 12.30735
## [377] 12.29731 12.28693 12.27622
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")